# pick out accession name for protein identified in both control and foxq1 up-regulated cell

import re
import pandas as pd
import os

datafile_path = os.path.join('data_src','ProteinSummary.xlsx')

xlfile = pd.ExcelFile(datafile_path)
# parse the venn_result sheet
df_venn = xlfile.parse(sheet_name=-1)

#虽然下面的方法可以顺次填充input，foxq1进identified by，但是用处其实不大。
def gen_str():
    n= 0
    list_from = ['input','foxq1']
    while True:
        yield list_from[n]
        n = n+1
        if n>=len(list_from):
            n = 0


generator = gen_str()
#df_venn['Identified by'] = df_venn['Identified by'].apply(lambda e:next(generator))
df_venn = df_venn.drop(labels=['Identified by', 'Total'],axis=1)
df_venn.dropna(inplace=True)

df_venn[['acc_num','acc_name']] = df_venn['Accession'].str.split(pat='|',expand=True)[[1,2]]
df_venn['acc_name'] = df_venn['acc_name'].str.split(pat='_',expand=True)[0]

# uniprot id convert to ncbi gene id for further analysis
# 直接用网上的api不香么，bioconductor左右横跳……
dict_mapper = pd.read_csv(os.path.join('data_src','mapping_uniprot_geneid.csv'),dtype=str).set_index("From")
dict_mapper = dict_mapper['To'].to_dict()
df_venn['geneid'] = df_venn['acc_num'].map(dict_mapper)

df_venn.to_csv(os.path.join('data_src','df_venn.csv'),index=False)
